<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
		<head>
			<!-- template designed by Marco Von Ballmoos -->
			<title>Docs For Class Psa_Logger</title>
			<link rel="stylesheet" href="../media/stylesheet.css" />
			<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'/>
		</head>
		<body>
			<div class="page-body">			
<h2 class="class-name"><img src="../media/images/Class_logo.png"
														alt=" Class"
														title=" Class"
														style="vertical-align: middle"> Psa_Logger</h2>

<a name="sec-description"></a>
<div class="info-box">
	<div class="info-box-title">Description</div>
	<div class="nav-bar">
					<span class="disabled">Description</span> |
															<a href="#sec-method-summary">Methods</a> (<a href="#sec-methods">details</a>)
						
					</div>
	<div class="info-box-body">
        		<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">This class handles logging.</p>
<p class="description"><p>Logs are by default written to database into <em>psa_log</em> table but can be also  written to file that depends on settings in <a href="../psa/_config.php.html">config.php</a> file.</p><p>This class implements <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singleton pattern</a>  to ensure that there is only one instance of the <a href="../psa/Psa_Logger.html">Psa_Logger</a> object and  to allow that this single instance is easily accessible from any scope.  You should not make instance of <a href="../psa/Psa_Logger.html">Psa_Logger</a> object with <var>new</var> operator  instead call static method <a href="../psa/Psa_Logger.html#methodget_instance">get_instance()</a>.</p><p><strong>Examples</strong></p><p><strong>1)</strong> Log a single message.  <div class="src-code"><ol><li><div class="src-line">&nbsp;<span class="src-id"><a href="../psa/Psa_Logger.html">Psa_Logger</a></span><span class="src-sym">::</span><a href="../psa/Psa_Logger.html#methodget_instance">get_instance</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">-&gt;</span><a href="../psa/Psa_Logger.html#methodlog">log</a><span class="src-sym">(</span><span class="src-str">&quot;Log&nbsp;message&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
</ol></div></p><p><strong>2)</strong> If you want to extend this class you should write your child class like this:  <div class="src-code"><ol><li><div class="src-line">&nbsp;<span class="src-php">&lt;?php</span></div></li>
<li><div class="src-line">&nbsp;<span class="src-key">class&nbsp;</span><span class="src-id">Child_of_Psa_Logger&nbsp;</span><span class="src-key">extends&nbsp;</span><a href="../psa/Psa_Logger.html">Psa_Logger</a></div></li>
<li><div class="src-line">&nbsp;<span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;returns&nbsp;Child_of_Psa_Logger</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">public&nbsp;</span><span class="src-key">static&nbsp;</span><span class="src-key">function&nbsp;</span><span class="src-id">get_instance</span><span class="src-sym">(</span><span class="src-sym">)</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-id">parent</span><span class="src-sym">::</span><span class="src-id">get_instance</span><span class="src-sym">(</span>__CLASS__<span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;your&nbsp;method&nbsp;for&nbsp;generate&nbsp;database&nbsp;query</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">function&nbsp;</span><span class="src-id">format_database_log_query</span><span class="src-sym">(</span><span class="src-var">$log_storage</span><span class="src-sym">)</span><span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;your&nbsp;method&nbsp;for&nbsp;parameters&nbsp;for&nbsp;prepared&nbsp;query</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">function&nbsp;</span><span class="src-id">format_database_log_query_params</span><span class="src-sym">(</span><span class="src-var">$log_data</span><span class="src-sym">)</span><span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line">&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;<span class="src-comm">//&nbsp;call&nbsp;log&nbsp;method</span></div></li>
<li><div class="src-line">&nbsp;<span class="src-id">Child_of_Psa_Logger</span><span class="src-sym">::</span><span class="src-id">get_instance</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">-&gt;</span><a href="http://www.php.net/log">log</a><span class="src-sym">(</span><span class="src-str">&quot;log&nbsp;message&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;<span class="src-php">?&gt;</span></div></li>
</ol></div></p></p>
		<p class="notes">
			Located in <a class="field" href="_scripts---Psa_Logger.class.php.html">/scripts/Psa_Logger.class.php</a> (line <span class="field"><a href="../__filesource/fsource_psa__scriptsPsa_Logger.class.php.html#a72">72</a></span>)
		</p>
		
				
		<pre>Psa_Singleton
   |
   --Psa_Logger</pre>
	
			</div>
</div>




	<a name="sec-method-summary"></a>
	<div class="info-box">
		<div class="info-box-title">Method Summary</span></div>
		<div class="nav-bar">
			<a href="#sec-description">Description</a> |
												<span class="disabled">Methods</span> (<a href="#sec-methods">details</a>)
		</div>
		<div class="info-box-body">			
			<div class="method-summary">
																																				<div class="method-definition">
					<img src="../media/images/StaticMethod.png" alt=" "/>
											static <span class="method-result"><a href="../psa/Psa_Logger.html">object Psa_Logger</a></span>
										<a href="#get_instance" title="details" class="method-name">get_instance</a>
											([<span class="var-type"></span>&nbsp;<span class="var-name">$class</span> = <span class="var-default">null</span>])
									</div>
																												<div class="method-definition">
					<img src="../media/images/Method.png" alt=" "/>
											<span class="method-result">string</span>
										<a href="#format_database_log_query" title="details" class="method-name">format_database_log_query</a>
											(<span class="var-type">int</span>&nbsp;<span class="var-name">$log_storage</span>)
									</div>
																<div class="method-definition">
					<img src="../media/images/Method.png" alt=" "/>
											<span class="method-result">array</span>
										<a href="#format_database_log_query_params" title="details" class="method-name">format_database_log_query_params</a>
											(<span class="var-type"></span>&nbsp;<span class="var-name">&$log_data</span>, <span class="var-type">array</span>&nbsp;<span class="var-name">$log_data</span>, <span class="var-type">int</span>&nbsp;<span class="var-name">$log_storage</span>)
									</div>
																<div class="method-definition">
					<img src="../media/images/Method.png" alt=" "/>
											<span class="method-result">string</span>
										<a href="#format_file_log" title="details" class="method-name">format_file_log</a>
											(<span class="var-type">array</span>&nbsp;<span class="var-name">$log_data</span>, <span class="var-type">int</span>&nbsp;<span class="var-name">$log_storage</span>)
									</div>
																								<div class="method-definition">
					<img src="../media/images/Method.png" alt=" "/>
											<span class="method-result">int</span>
										<a href="#log" title="details" class="method-name">log</a>
											(<span class="var-type">array|string</span>&nbsp;<span class="var-name">$log_data</span>, [<span class="var-type">int|string</span>&nbsp;<span class="var-name">$log_storage</span> = <span class="var-default">'psa_default'</span>])
									</div>
											</div>
		</div>
	</div>		

	
	<a name="sec-methods"></a>
	<div class="info-box">
		<div class="info-box-title">Methods</div>
		<div class="nav-bar">
			<a href="#sec-description">Description</a> |
													<a href="#sec-method-summary">Methods</a> (<span class="disabled">details</span>)
						
		</div>
		<div class="info-box-body">
			<A NAME='method_detail'></A>
<a name="methodget_instance" id="get_instance"><!-- --></a>
<div class="evenrow">
	
	<div class="method-header">
		<img src="../media/images/StaticMethod.png" />
		<span class="method-title">static get_instance</span> (line <span class="line-number"><a href="../__filesource/fsource_psa__scriptsPsa_Logger.class.php.html#a104">104</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Returns instance of the <a href="../psa/Psa_Logger.html">Psa_Logger</a> object.</p>
<p class="description"><p>You should statically call this method with scope resolution operator (::) which gives you  access to the logging object from anywhere in your application, whether it is from a function,  a method, or the global scope.  Example:  <div class="src-code"><ol><li><div class="src-line">&nbsp;<span class="src-id"><a href="../psa/Psa_Logger.html">Psa_Logger</a></span><span class="src-sym">::</span><a href="../psa/Psa_Logger.html#methodget_instance">get_instance</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">-&gt;</span><a href="../psa/Psa_Logger.html#methodlog">log</a><span class="src-sym">(</span><span class="src-str">&quot;Log&nbsp;message&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
</ol></div></p></p>
	<ul class="tags">
				<li><span class="field">access:</span> public</li>
			</ul>
	
	<div class="method-signature">
		<span class="method-result"><a href="../psa/Psa_Logger.html">object Psa_Logger</a></span>
		<span class="method-name">
			get_instance
		</span>
					([<span class="var-type"></span>&nbsp;<span class="var-name">$class</span> = <span class="var-default">null</span>])
			</div>
	
			<ul class="parameters">
					<li>
				<span class="var-type"></span>
				<span class="var-name">$class</span>			</li>
				</ul>
		
			
	</div>
<a name="methodformat_database_log_query" id="format_database_log_query"><!-- --></a>
<div class="oddrow">
	
	<div class="method-header">
		<img src="../media/images/Method.png" />
		<span class="method-title">format_database_log_query</span> (line <span class="line-number"><a href="../__filesource/fsource_psa__scriptsPsa_Logger.class.php.html#a284">284</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Returns sql insert query that writes log to database.</p>
<p class="description"><p>Override this method if you want to change log format in the database. You will have  to manually alter log database table if you wish to add some new columns into it.  This method has to have matching <a href="../psa/Psa_Logger.html#methodformat_database_log_query_params">format_database_log_query_params()</a> method.</p></p>
	<ul class="tags">
				<li><span class="field">see:</span> <a href="../psa/Psa_Logger.html#methodlog">Psa_Logger::log()</a></li>
				<li><span class="field">see:</span> <a href="../psa/Psa_Logger.html#methodformat_file_log">Psa_Logger::format_file_log()</a></li>
				<li><span class="field">see:</span> <a href="../psa/Psa_Logger.html#methodformat_database_log_query_params">Psa_Logger::format_database_log_query_params()</a></li>
				<li><span class="field">access:</span> protected</li>
			</ul>
	
	<div class="method-signature">
		<span class="method-result">string</span>
		<span class="method-name">
			format_database_log_query
		</span>
					(<span class="var-type">int</span>&nbsp;<span class="var-name">$log_storage</span>)
			</div>
	
			<ul class="parameters">
					<li>
				<span class="var-type">int</span>
				<span class="var-name">$log_storage</span><span class="var-description">: see <a href="../psa/Psa_Logger.html#methodlog">log()</a> method</span>			</li>
				</ul>
		
			
	</div>
<a name="methodformat_database_log_query_params" id="format_database_log_query_params"><!-- --></a>
<div class="evenrow">
	
	<div class="method-header">
		<img src="../media/images/Method.png" />
		<span class="method-title">format_database_log_query_params</span> (line <span class="line-number"><a href="../__filesource/fsource_psa__scriptsPsa_Logger.class.php.html#a304">304</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Returns array of parameters for prepared query from format_database_log_query() method.</p>
	<ul class="tags">
				<li><span class="field">see:</span> <a href="../psa/Psa_Logger.html#methodlog">Psa_Logger::log()</a></li>
				<li><span class="field">see:</span> <a href="../psa/Psa_Logger.html#methodformat_file_log">Psa_Logger::format_file_log()</a></li>
				<li><span class="field">see:</span> <a href="../psa/Psa_Logger.html#methodformat_database_log_query">Psa_Logger::format_database_log_query()</a></li>
				<li><span class="field">access:</span> protected</li>
			</ul>
	
	<div class="method-signature">
		<span class="method-result">array</span>
		<span class="method-name">
			format_database_log_query_params
		</span>
					(<span class="var-type"></span>&nbsp;<span class="var-name">&$log_data</span>, <span class="var-type">array</span>&nbsp;<span class="var-name">$log_data</span>, <span class="var-type">int</span>&nbsp;<span class="var-name">$log_storage</span>)
			</div>
	
			<ul class="parameters">
					<li>
				<span class="var-type">array</span>
				<span class="var-name">$log_data</span><span class="var-description">: see <a href="../psa/Psa_Logger.html#methodlog">log()</a> method</span>			</li>
					<li>
				<span class="var-type">int</span>
				<span class="var-name">$log_storage</span><span class="var-description">: see <a href="../psa/Psa_Logger.html#methodlog">log()</a> method</span>			</li>
					<li>
				<span class="var-type"></span>
				<span class="var-name">&$log_data</span>			</li>
				</ul>
		
			
	</div>
<a name="methodformat_file_log" id="format_file_log"><!-- --></a>
<div class="oddrow">
	
	<div class="method-header">
		<img src="../media/images/Method.png" />
		<span class="method-title">format_file_log</span> (line <span class="line-number"><a href="../__filesource/fsource_psa__scriptsPsa_Logger.class.php.html#a331">331</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Formats log message that will be written into the log file.</p>
<p class="description"><p>Override this method if you want to change log format.</p></p>
	<ul class="tags">
				<li><span class="field">see:</span> format_database_log()</li>
				<li><span class="field">see:</span> <a href="../psa/Psa_Logger.html#methodlog">Psa_Logger::log()</a></li>
				<li><span class="field">access:</span> protected</li>
			</ul>
	
	<div class="method-signature">
		<span class="method-result">string</span>
		<span class="method-name">
			format_file_log
		</span>
					(<span class="var-type">array</span>&nbsp;<span class="var-name">$log_data</span>, <span class="var-type">int</span>&nbsp;<span class="var-name">$log_storage</span>)
			</div>
	
			<ul class="parameters">
					<li>
				<span class="var-type">array</span>
				<span class="var-name">$log_data</span><span class="var-description">: see <a href="../psa/Psa_Logger.html#methodlog">log()</a> method</span>			</li>
					<li>
				<span class="var-type">int</span>
				<span class="var-name">$log_storage</span><span class="var-description">: see <a href="../psa/Psa_Logger.html#methodlog">log()</a> method</span>			</li>
				</ul>
		
			
	</div>
<a name="methodlog" id="log"><!-- --></a>
<div class="evenrow">
	
	<div class="method-header">
		<img src="../media/images/Method.png" />
		<span class="method-title">log</span> (line <span class="line-number"><a href="../__filesource/fsource_psa__scriptsPsa_Logger.class.php.html#a164">164</a></span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Writes logs.</p>
<p class="description"><p>Writes a log record to database or file. This depends on settings (<var>$PSA_CFG['logging']</var>)  in <a href="../psa/_config.php.html">config.php</a>. First argument can be array or string. If is a string it is written to the log.  If it is array some other values in log record can be set. Here is example array with all  available elements and example values that can be used as first argument for this method.  <pre> Array
 (
     [user_id] => 5                // id of user
     [username] => john            // username
     [group_id] => 3               // id of group
     [groupname] => test           // group name
     [message] => new user created // log message
     [function] => Psa_User::save  // method or function name that created log
     [level] => 2                  // Log level, default 1. Integer. If greater than <var>$PSA_CFG['logging']['level']</var> log will not be saved.
     [type] => general             // This is just mark. Types used by psa: 'general' - default, 'error', 'warning', 'SQL_error', 'exception'
 )</pre>  All array elements are optional.</p><p><strong>Example:</strong></p><p><div class="src-code"><ol><li><div class="src-line">&nbsp;<span class="src-php">&lt;?php</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;<span class="src-comm">//&nbsp;set&nbsp;data&nbsp;to&nbsp;log</span></div></li>
<li><div class="src-line">&nbsp;<span class="src-var">$log_data</span><span class="src-sym">[</span><span class="src-str">'user_id'</span><span class="src-sym">]&nbsp;&nbsp;</span>=&nbsp;<span class="src-num">123</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;<span class="src-var">$log_data</span><span class="src-sym">[</span><span class="src-str">'username'</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-str">'abc'</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;<span class="src-var">$log_data</span><span class="src-sym">[</span><span class="src-str">'message'</span><span class="src-sym">]&nbsp;&nbsp;</span>=&nbsp;<span class="src-str">'test&nbsp;message'</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;<span class="src-var">$log_data</span><span class="src-sym">[</span><span class="src-str">'function'</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-str">'some_method'</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;<span class="src-var">$log_data</span><span class="src-sym">[</span><span class="src-str">'level'</span><span class="src-sym">]&nbsp;&nbsp;&nbsp;&nbsp;</span>=&nbsp;<span class="src-num">1</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;<span class="src-var">$log_data</span><span class="src-sym">[</span><span class="src-str">'type'</span><span class="src-sym">]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>=&nbsp;<span class="src-str">'some_type'</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;<span class="src-comm">//&nbsp;write&nbsp;log</span></div></li>
<li><div class="src-line">&nbsp;<span class="src-id"><a href="../psa/Psa_Logger.html">Psa_Logger</a></span><span class="src-sym">::</span><a href="../psa/Psa_Logger.html#methodget_instance">get_instance</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">-&gt;</span><a href="../psa/Psa_Logger.html#methodlog">log</a><span class="src-sym">(</span><span class="src-var">$log_data</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;<span class="src-php">?&gt;</span></div></li>
</ol></div></p></p>
	<ul class="tags">
				<li><span class="field">return:</span> 0 for failure, 1 for success, -1 logging is disabled or the log level for message is set too low  (bigger number than <var>$PSA_CFG['logging']['max_log_level']</var>).</li>
				<li><span class="field">see:</span> <a href="../psa/_config.php.html">config.php</a></li>
				<li><span class="field">see:</span> <a href="../psa/Psa_Logger.html#methodget_instance">Psa_Logger::get_instance()</a></li>
				<li><span class="field">see:</span> format_database_log()</li>
				<li><span class="field">see:</span> <a href="../psa/Psa_Logger.html#methodformat_file_log">Psa_Logger::format_file_log()</a></li>
				<li><span class="field">access:</span> public</li>
			</ul>
	
	<div class="method-signature">
		<span class="method-result">int</span>
		<span class="method-name">
			log
		</span>
					(<span class="var-type">array|string</span>&nbsp;<span class="var-name">$log_data</span>, [<span class="var-type">int|string</span>&nbsp;<span class="var-name">$log_storage</span> = <span class="var-default">'psa_default'</span>])
			</div>
	
			<ul class="parameters">
					<li>
				<span class="var-type">array|string</span>
				<span class="var-name">$log_data</span><span class="var-description">: array with data to be logged or log message only. If is a string, that string  is used as message to be logged.</span>			</li>
					<li>
				<span class="var-type">int|string</span>
				<span class="var-name">$log_storage</span><span class="var-description">: storage for the log. This is index of <var>$PSA_CFG['logging']['storage']</var>  array in <a href="../psa/_config.php.html">config.php</a>. Default is 'psa_default'.</span>			</li>
				</ul>
		
			
	</div>
						
		</div>
	</div>

	
	<p class="notes" id="credit">
		Documentation generated on Thu, 21 Oct 2010 01:40:51 +0200 by <a href="http://www.phpdoc.org" target="_blank">phpDocumentor 1.4.3</a>
	</p>
	</div></body>
</html>